package lormi.meipin.service.impl;


import lormi.meipin.common.LMRongYunAPI;
import lormi.meipin.dto.CurrencyDto;
import lormi.meipin.entity.FocusTalent;
import lormi.meipin.exception.LMException;
import lormi.meipin.service.BaseService;
import lormi.meipin.service.IFocusTalentService;
import lormi.meipin.vo.TalentSearchVo;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FocusTalentService extends BaseService implements IFocusTalentService{

	@Override
	public void focusTalent(Integer merId, Integer memId) throws LMException {
		if (focusTalentMapper.selectByMeridAndMemid(merId, memId, 1)!=null) {
			throw new LMException(100022);
		}
		if (focusTalentMapper.insert(new FocusTalent(merId,memId,1))<1) {
			throw new LMException(100035);
		}
		//推送通知
		LMRongYunAPI.push(memId+"",merChantMapper.selectByMerId(merId).getName(), 11);
		
	}

	@Override
	public void cancelFocusTalent(Integer merId, Integer memId) throws LMException {
		FocusTalent focusTalent = focusTalentMapper.selectByMeridAndMemid(merId, memId, 1);
		if (focusTalent==null) {
			throw new LMException(170005);
		}
		if (focusTalentMapper.deleteByPrimaryKey(focusTalent.getId())<1) {
			throw new LMException(130010);
		}
	}

	@Override
	public List<TalentSearchVo> getFocusList(CurrencyDto dto) throws LMException {
		List<TalentSearchVo> list = talentMapper.getFocusTalentVo(dto.getUserid(),dto.getOffset(),dto.getPagesize());
		if (list==null || list.size()<1) {
			throw new LMException(100028);
		}
		return list;
	}

	
}
